#pragma once
#include<iostream>
using namespace std;
namespace x
{
	class string
	{
	public:

		void reserve(size_t n)
		{
			char* tmp = new char[n + 1];
			strcpy(tmp,_str);
			delete[] _str;
			_capacity = n;
			_str = tmp;
		}

		char* begin() const
		{
			return _str;
		}

		char* end() const
		{
			return _str + _size;
		}

		string(const char* str = "")
		{
			_size = strlen(str);
			_capacity = _size;
			_str = new char[_capacity + 1];
			strcpy(_str, str);
		}

		string(const string& s)
		{
			_str = new char[s._capacity + 1];
			strcpy(_str, s._str);
			_capacity = s._capacity;
			_size = s._size;
		}

		string& operator=(const string& s)
		{
			if (this != &s)
			{
				delete[] _str;
				_str = new char[s._capacity + 1];
				strcpy(_str, s._str);
				_capacity = s._capacity;
				_size = s._size;
			}
			return *this;
		}

		string& operator+=(char c);

		

		~string()
		{
			delete[] _str;
			_str = nullptr;
			_size = _capacity = 0;
		}

		char* c_str()
		{
			return _str;
		}
		
	private:
		char* _str;
		size_t _size;
		size_t _capacity;
	};
	void test_string();
	ostream& operator<<(ostream& out, const string& s);
	istream& operator>>(istream& in, string& s);
}
